package edu.kit.aifb.ldstream.stat.distrib;

import java.io.Serializable;

public class BinomialDistribution implements IDistribution, Serializable {

	private static final long serialVersionUID = 5994344306889982692L;

	private double p;
	private int samples;
	
	public BinomialDistribution(double p, int samples){
		this.p = p;
		this.samples = samples;
	}
	

	/**
	 * @return the p
	 */
	public double getP() {
		return p;
	}

	/**
	 * @return the samples
	 */
	public int getSamples() {
		return samples;
	}

	@Override
	public int getDistributionType() {
		return IDistribution.BINOMIAL;
	}
	
	public int hashCode(){
		return (int) (this.p * this.samples * IDistribution.BINOMIAL);
	}
	
	public boolean equals(Object o){
		if(o instanceof BinomialDistribution){
			BinomialDistribution bd = (BinomialDistribution) o;
			return (Math.abs(this.p -bd.p) < 0.01d) && (this.samples == bd.samples); 
		}
		return false;
	}

	public String toString(){
		StringBuilder sb = new StringBuilder(" BinomialDistribution with ");
		sb.append("probability: ");
		sb.append(this.p);
		sb.append(" and ");
		sb.append(this.samples);
		sb.append(" samples ");
		return sb.toString();
	}
}
